<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<script type="text/javascript" src="<c:url value="/resources/spring/Spring.js" />"></script>
<h1>User Results</h1>
<div>
<c:if test="${not empty userList}">
	<table>
		<thead>
			<tr>
				<th>User Name</th>
				<th>Login Name</th>
				<th>Remove</th>
				<th>Update</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach var="user" items="${userList}">
				<tr>
					<td>${user.userName}</td>
					<td>${user.loginName}</td>
					<td>
						<spring:url var="userUrl" value="/user/{id}">
							<spring:param name="id" value="${user.id}"/>
						</spring:url>
						<form:form action="${userUrl}" method="delete">
							<button type="submit">Cancel</button>
						</form:form>
					</td>
					<td></td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<div>
		<div>
			<c:if test="${0 != pageCondition.page}">
				<a id="prevResultsLink" href="../user/list?size=${pageCondition.size}&page=0">First Page</a>
				<script type="text/javascript">
					Spring.addDecoration(new Spring.AjaxEventDecoration({
						elementId: "prevResultsLink",
						event: "onclick",
						params: {fragments: "body"}
					}));
				</script>
			</c:if>
			<c:if test="${pageCondition.page > 0 && 0 != pageCondition.page}">
				<a id="prevResultsLink" href="../user/list?size=${pageCondition.size}&page=${pageCondition.page - 1}">Previous Page</a>
				<script type="text/javascript">
					Spring.addDecoration(new Spring.AjaxEventDecoration({
						elementId: "prevResultsLink",
						event: "onclick",
						params: {fragments: "body"}
					}));
				</script>
			</c:if>
			<c:if test="${pageCondition.totalPage != 0 && pageCondition.totalPage-1 > pageCondition.page && pageCondition.totalPage-1 != pageCondition.page}">
				<a id="moreResultsLink" href="../user/list?size=${pageCondition.size}&page=${pageCondition.page + 1}">Next Page</a>
				<script type="text/javascript">
					Spring.addDecoration(new Spring.AjaxEventDecoration({
						elementId: "moreResultsLink",
						event: "onclick",
						params: {fragments: "body"}		
					}));
				</script>
			</c:if>		
			<c:if test="${pageCondition.totalPage != 0 && pageCondition.totalPage-1 != pageCondition.page}">
				<a id="prevResultsLink" href="../user/list?size=${pageCondition.size}&page=${pageCondition.totalPage - 1}">Last Page</a>
				<script type="text/javascript">
					Spring.addDecoration(new Spring.AjaxEventDecoration({
						elementId: "prevResultsLink",
						event: "onclick",
						params: {fragments: "body"}
					}));
				</script>
			</c:if>
		</div>
	</div>
</c:if>
<c:if test="${empty userList}">
	<div>No hotels found</div>
</c:if>
</div>	
